class Solution {
public:
    string decodeMessage(string key, string message) {
        int tag = 0, i = 0, cnt = 0;
        char words[26];

        while (i < key.size())
        {
            
            if (isalpha(key[i]))
            {
                if ((tag>>key[i] - 'a' &1) != 1)
                {
                    tag |= 1 << key[i] - 'a';
                    words[key[i] - 'a'] = cnt++ + 'a';
                }
            }
            i++;
        }
        for (int j = 0; j < message.size(); j++)
        {
            if (isalpha(message[j]))
                message[j] = words[message[j] - 'a'];
        }
        return message;
    }
};